package mamma.action;

import java.util.List;
import java.util.Map;

import mamma.common.PageNavigator;
import mamma.dao.BoardDao;
import mamma.dao.PhotoDao;
import mamma.vo.BoardComment;
import mamma.vo.BoardVo;
import mamma.vo.MemberVo;

import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;

public class BoardAction extends ActionSupport implements SessionAware {

	private Map<String, Object> session;
	private MemberVo memberVo;
	private String savedFile;
	private int currentPage = 1;
	private PageNavigator navi;
	//board
	private BoardVo boardVo;
	private int boardNum;
	private BoardComment comment;
	private int commentNum;
	private List<BoardVo> boardList;
	private List<BoardComment> commentList;
	private String searchText;
	private String content;
	private String state;
	
	private String email;
	
/* board 부분 */
	
	/* board 쓰기*/
	public String writeBoard(){
		memberVo =  (MemberVo)session.get("login");
		System.out.println("login에서 추춣값 ");
	
		boardVo.setState(state);
		boardVo.setNickname(memberVo.getNickname());
		boardVo.setEmail(memberVo.getEmail());
		
		System.out.println(boardVo);
		BoardDao dao = new BoardDao();
		dao.insertBoard(boardVo);
		

		return SUCCESS;
	}
	/* board 하나 읽기*/
	public String readBoard(){
		System.out.println("*******************************************readBoard의 boardNum"+ boardNum);
		memberVo = (MemberVo)session.get("login");
		boardVo = new BoardDao().getBoard(boardNum);
		
		MemberVo temp =  new PhotoDao().getMember(boardVo.getEmail());
		savedFile = new PhotoDao().gtProfile(temp.getProfile_id());
		System.out.println("*******************************************readBoard의 savedFile"+ savedFile);

		return SUCCESS;
	}
	/* board 삭제*/
	public String deleteBoard(){
		new BoardDao().deleteBoard(boardNum);
		return SUCCESS;
	}
	/* board 수정화면*/
	public String updateBoardForm(){
		boardVo = new BoardDao().getBoard(boardNum);
		boardNum = boardVo.getBoardNum();
		
		MemberVo temp =  new PhotoDao().getMember(boardVo.getEmail());
		savedFile = new PhotoDao().gtProfile(temp.getProfile_id());
		System.out.println(savedFile);
		return SUCCESS;
	}
	/* board 수정*/
	
	public String boardUpdate(){
		System.out.println(boardVo);
		new BoardDao().updateBoard(boardVo);
		boardNum = boardVo.getBoardNum();
		
		return SUCCESS;
	}
	
	
	/* comment 리스트*/
	public String commentList(){
		
		commentList = new BoardDao().commentList(boardNum);
		
		return SUCCESS;
	}
	public String deleteComment(){
		memberVo = (MemberVo)session.get("login");
		
		new BoardDao().deleteComment(commentNum,memberVo.getEmail());
		commentList();
		return SUCCESS;
	}
	public String writeComment(){
		memberVo = (MemberVo)session.get("login");
		String savedFile = new PhotoDao().gtProfile(memberVo.getProfile_id());
		
		
		
		comment = new BoardComment();
		comment.setContent(content);
		comment.setEmail(memberVo.getEmail());
		comment.setNickname(memberVo.getNickname());
		comment.setBoardNum(boardNum);
		comment.setSavedFile(savedFile);
		new BoardDao().writeComment(comment);
		System.out.println("쓰기 끝");
		commentList();		
		return SUCCESS;
	}
	public String boardList(){
		//searchText 부분( 나중에 완성)
		
		System.out.println("boardList메서드에서의 Stater값"+state);
		
		boardList = new BoardDao().boardList(state);
		return SUCCESS;
	}
	public String goBoardList(){
		memberVo = (MemberVo)session.get("login");
		memberVo = new PhotoDao().getMember(memberVo.getEmail());
		
		if (state==null){
			state = memberVo.getHometown();
			System.out.println("state값 = null"+state);
		}
		System.out.println("goBoardList"+ state);
		return SUCCESS;
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}


	public MemberVo getMemberVo() {
		return memberVo;
	}

	public void setMemberVo(MemberVo memberVo) {
		this.memberVo = memberVo;
	}

	public String getSavedFile() {
		return savedFile;
	}

	public void setSavedFile(String savedFile) {
		this.savedFile = savedFile;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public PageNavigator getNavi() {
		return navi;
	}

	public void setNavi(PageNavigator navi) {
		this.navi = navi;
	}

	public BoardVo getBoardVo() {
		return boardVo;
	}

	public void setBoardVo(BoardVo boardVo) {
		this.boardVo = boardVo;
	}

	public int getBoardNum() {
		return boardNum;
	}

	public void setBoardNum(int boardNum) {
		this.boardNum = boardNum;
	}

	public BoardComment getComment() {
		return comment;
	}

	public void setComment(BoardComment comment) {
		this.comment = comment;
	}

	public int getCommentNum() {
		return commentNum;
	}

	public void setCommentNum(int commentNum) {
		this.commentNum = commentNum;
	}

	public List<BoardVo> getBoardList() {
		return boardList;
	}

	public void setBoardList(List<BoardVo> boardList) {
		this.boardList = boardList;
	}

	public List<BoardComment> getCommentList() {
		return commentList;
	}

	public void setCommentList(List<BoardComment> commentList) {
		this.commentList = commentList;
	}

	public String getSearchText() {
		return searchText;
	}

	public void setSearchText(String searchText) {
		this.searchText = searchText;
	}

	public Map<String, Object> getSession() {
		return session;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	
	
}
